package com.woniuxy.mapper;

import com.woniuxy.pojo.Dept;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.mapping.FetchType;

import java.util.List;

@Mapper
public interface DeptMapper {
    @Insert("INSERT INTO dept(deptno,dname,loc)VALUES(#{deptno},#{dname},#{loc})")
    public void add(Dept dept);
    @Delete("DELETE FROM dept WHERE deptno=#{deptno}")
    public void delete(byte deptno);
    @Update("UPDATE dept SET dname=#{dname},loc=#{loc} WHERE deptno=#{deptno}")
    public void update(Dept dept);
    @Select("SELECT * FROM dept")
    public List<Dept> selectAll();
    @Results({
            @Result(property = "deptno", column = "deptno"),
            @Result(property = "dname", column = "dname"),
            @Result(property = "loc", column = "loc"),
            @Result(property = "emps",many = @Many(select = "com.woniuxy.mapper.EmpMapper.selectEmpsByDeptno",fetchType = FetchType.EAGER),column = "deptno")
    })
    @Select("SELECT * FROM dept WHERE deptno=#{deptno}")
    public Dept selectOne(byte deptno);
    @Select("SELECT * FROM dept WHERE deptno=#{deptno}")
    public Dept selectDeptByDeptnoWithStep(@Param("deptno") byte deptno);


}
